<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:include="include :: appHeader"></head>
<body ontouchstart style="background-color:#f9fafc"
      th:style="|background-image: url(@{/img/bg.png}); background-repeat: no-repeat;background-size: cover;background-attachment: fixed;|">

<div class="app-hd" style="margin-top: 60px">
    <h1 class="app-second-title" th:if="${profile == 'test'}"
        style="color: red; font-weight: bold;font-size: 60px; -webkit-text-stroke: 1px black;">(测试)</h1>
    <h1 class="app-second-title" th:if="${profile == 'dev'}"
        style="color: red; font-weight: bold;font-size: 60px; -webkit-text-stroke: 1px black;">(开发)</h1>
    <h1 class="app-second-title">辽宁忠旺机械设备制造有限公司</h1>
    <div style="text-align: center;"><img th:src="@{/img/logo.png}" width="124.5px" height="75px"
                                          src="/static/img/logo.png"></div>
    <h1 class="app-second-title">二维码转序系统</h1>
</div>
<div class="app-bd">
    <form id="login-form">
        <div class="weui-cells weui-cells_form">
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input id="login-name" name="account" class="weui-input" type="text" data-required="true"
                           placeholder="工作证号">
                </div>
            </div>
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <input id="login-password" name="pwd" class="weui-input" type="password" data-required="true"
                           placeholder="密码">
                </div>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__bd">
                <input id="login-auto-login" name="auto-login" type="checkbox" data-required="true"/> 自动登录
            </div>
        </div>
    </form>
    <div class="weui-btn-area">
        <a id="btn-login" href="javascript:void(0);" class="weui-btn weui-btn_primary" style="margin-top: 35px">登录</a>
    </div>
</div>

<div th:include="include :: appFooter"></div>
<script th:inline="javascript">
    $(function () {
        $("#login-name").val(window.localStorage.getItem('account'));
        $("#login-password").val(window.localStorage.getItem('pwd'));
        let loginModel = window.localStorage.getItem('isAutoLogin');
        if (loginModel == 'true') {
            document.getElementById('login-auto-login').checked = true;
            login();
        }
        $("#btn-login").click(function () {
            login();
        });
    })
    function login(){
        if (document.getElementById('login-auto-login').checked) {
            window.localStorage.setItem('isAutoLogin', 'true');
        }else{
            window.localStorage.setItem('isAutoLogin', 'false');
        }
        if ($("#login-name").val() == '') {
            $.box.toptip_w('请输入工作证！');
            return;
        }
        if ($("#login-password").val() == '') {
            $.box.toptip_w('请输入密码！');
            return;
        }
        $.operate.validSubmit({
            url: ctx + 'login',
            form: $("#login-form"),
            data: new FormData($("#login-form")[0]),
            fun: function (res) {
                if (res.type === 'SUCCESS') {
                    window.localStorage.setItem('account', res.data.account);
                    window.localStorage.setItem('pwd', res.data.pwd);
                    location.href = ctx + "index";
                } else {
                    $.box.toptip_w(res.msg);
                }
            }
        });
    }
</script>
</body>
</html>